import requests
import json
from lxml import etree

#获取基金列表
class found_get:

    #获取基金列表方式1 部分基金
    def get_new_foundlist1(self):
        response  = requests.get("http://fund.eastmoney.com/Data/Fund_JJJZ_Data.aspx?page=1,9999")
        rsp=response.content.decode("utf-8")
        rsp = rsp[7:]
        rsp = rsp[rsp.find("data"):(rsp.find("count")-1)]
        rsp = "{"+rsp.replace("datas",'"datas"',1)+"}"
        params = json.loads(rsp)
        values_list = params["datas"]
        insert_list = []
        for element in values_list:
            insert_list.append(tuple(element[0:2]))
        return insert_list

    # 获取基金列表方式2，包含货币基金
    def get_new_foundlist2(self):
        response = requests.get("http://fund.eastmoney.com/js/fundcode_search.js")
        response.encoding = 'utf-8'
        text=response.text[9:-1]
        values_list = json.loads(text)
        insert_list = []
        for element in values_list:
            data=[]
            data.append(element[0])
            data.append(element[2])
            insert_list.append(tuple(data[0:2]))
        return insert_list


if __name__=="__main__":
    found_get = found_get();
    found_get. get_new_foundlist2()